package Q205

import java.util.*
import kotlin.collections.ArrayList
import java.util.HashMap




/**
 * 同构字符串
 * @author 23737
 * @date 2022.5.5
 */
class Main {

}

fun main() {
    val s = "egg"
    val t = "add"
    println(Solution().isIsomorphic(s, t))
}

//hashmap 进行映射
 class Solution {
    fun isIsomorphic(s: String, t: String): Boolean {
        if (s.length != t.length) {
            return false
        }
        val map = HashMap<Char, Char>()
        for (i in s.indices) {
            if (!map.containsKey(s[i])) {
                if (map.containsValue(t[i])) {
                    return false
                }
                map[s[i]] = t[i]
            } else {
                if (map[s[i]] != t[i]) {
                    return false
                }
            }
        }
        return true
    }
}